import subprocess
import random


# 设置要修改的网络接口的 MAC 地址和随机数范围
reg_key = r"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0003"
min_num = 1111
max_num = 9999

# 生成随机 MAC 地址
mac_address = "60AB611A"
random_num = random.randint(min_num, max_num)
new_mac_address = mac_address + str(random_num)

# 使用 reg 命令设置网络接口的 MAC 地址
subprocess.run(["reg", "delete", reg_key, "/v", "NetworkAddress", "/f"])
subprocess.run(["reg", "add", reg_key, "/v", "NetworkAddress", "/t", "REG_SZ", "/d", new_mac_address, "/f"])

# 使用 netsh 命令重启网络接口
interface_name = "以太网"
subprocess.run(["netsh", "interface", "set", "interface", interface_name, "disable"])
subprocess.run(["netsh", "interface", "set", "interface", interface_name, "enable"])
